package com.sunsy.authserver.service.impl;

import com.alibaba.fastjson.JSON;
import com.sunsy.authserver.beans.dto.LoginDto;
import com.sunsy.authserver.beans.po.UniformUser;
import com.sunsy.authserver.beans.vo.LoginVo;
import com.sunsy.authserver.service.LoginService;
import com.sunsy.authserver.service.UniformUserService;
import com.sunsy.authserver.util.JwtUtil;
import com.sunsy.authserver.util.MD5;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginServiceImpl implements LoginService {

    private RedisOperator redisOperator;
    private JwtUtil jwtUtil;
    private UniformUserService userService;

    @Autowired
    public void setUserService(UniformUserService userService){
        this.userService=userService;
    }

    @Autowired
    public void setJwtUtil(JwtUtil jwtUtil) {
        this.jwtUtil = jwtUtil;
    }

    @Autowired
    public void setRedisOperator(RedisOperator redisOperator) {
        this.redisOperator = redisOperator;
    }


    @Override
    public String generalLogin(LoginDto dto) {
        UniformUser user = userService.checkUser(dto);
        String code = MD5.toMD5(jwtUtil.createToken(JSON.toJSONString(dto)));
        redisOperator.set(code, user.getId().toString(), 30);
        return code;
    }

    @Override
    public LoginVo login(LoginDto dto) {
        return null;
    }


}
